﻿<?php

$str = $_GET['str'];
$fontpath= $_GET['fontpath'];
if($str==null||$str==''){
	return; 
}else{
	$str = iconv("GB2312", "UTF-8", $str);//为了支持中文
}


$Size = 72;

if($fontpath==null||$fontpath==''){//字体的路径
	$fontpath='JDFMAOKAI.ttf'; //可使用ttf字体
}

//动态计算文字占用图片大小
$txts = imagettfbbox($Size,0,$fontpath,$str);
//print_r($txts);die;

$YX1 = abs($txts[5])*0.23;
$YX2 = abs($txts[2])*0.02;
$IX = abs($txts[2])+$YX2;
$IY = abs($txts[5])+$YX1;

$im = imagecreate($IX,$IY);
$white = imagecolorallocate($im,0xFF,0xFF,0xFF);
imagecolortransparent($im,$white);
$black = imagecolorallocate($im,0x00,0x00,0x00);
imagettftext($im, $Size, 0, 0, $IY-$YX1,$black,"$fontpath",$str);
header("Content-type:image/png");
imagepng($im);// 输出到客户端
imagedestroy($im);
?>
